import numpy as np
import cvxpy as cp

c = np.array([20,14,16,36,32,30])
x = cp.Variable((6,1),integer = True)
T = np.array([[0.01,0.01,0.01,0.03,0.03,0.03],
              [0.02,0,0,0.05,0,0],
              [0,0.02,0,0,0.05,0],
              [0,0,0.03,0,0,0.08]])
TL = np.array([850,700,100,900])
obj = cp.Maximize(c.reshape((1,6)) * x)
con = [x >= 0, T*x <= TL.reshape(4,1)]
prob = cp.Problem(obj,con)
prob.solve()
print("最优值为：",prob.value)
print("最优解为：",x.value)

X = cp.Variable((5,1),integer = True)
c = np.array([160,210,60,80,180])
capital = np.array([210,300,150,130,260])
cons = [X[0] + X[1] + X[2] == 1, X[2] + X[3] == 1, X[4] <= X[0], 
        0 <= X, X <= 1, capital.reshape((1,5)) * X <= 600]
obj2 = cp.Maximize(c.reshape((1,5)) * X)
prob2 = cp.Problem(obj2,cons)
prob2.solve()
print("最优值为：",prob2.value)
print("最优解为：",X.value)